public class ThreadState {
    public static void main1(String[] args) {
        for (Thread.State state : Thread.State.values()) {
            System.out.println(state);
        }
    }


    public static void main2(String[] args) {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 100; i++) {

            }
        });

        System.out.println(t.getState());

        t.start();
        // isAlive()方法，处于不是 NEW 和 TERMINATED 的状态都是活着的
        while(t.isAlive()){
            System.out.println(t.getState());
        }

        System.out.println(t.getState());
    }


    public static void main3(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (locker){
                    while (true){
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        },"t1");

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (locker){
                    System.out.println("Jennie");
                }
            }
        },"t2");

        t1.start();
        t2.start();
    }

    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (locker){
                    while (true){
                        try {
                            locker.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        },"t1");

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (locker){
                    System.out.println("Jennie");
                }
            }
        },"t2");

        t1.start();
        t2.start();
    }

}